package chapter;

/**
 * Box 类重写 equals 方法，得到期望的结果
 * 使用 instanceof 来判断引用 obj对象的类型，是就转换成Box类
 */
public class Box1 {
    public int batch;
    public Box1(int batch){
        this.batch=batch;
    }
    @Override
    public boolean equals(Object object){
        if(object instanceof Box1){
            Box1 box1 = (Box1) object;
            return batch==box1.batch;
        }
        return false;
    }
    public static void main(String...args) {
        Box1 box1 = new Box1(1);
        Box1 box2 = new Box1(1);
        System.out.println(box1.equals(box2));
        System.out.println(box1==box2);
    }
}
